package org.auf.controllers;

import java.io.IOException;
import java.util.Collection;

import org.auf.core.Controller;
import org.auf.model.dao.IChatEventDAO;
import org.auf.model.dao.IEventDAO;
import org.auf.model.jdbc.ChatEventDAOJDBC;
import org.auf.model.jdbc.EventDAOJDBC;
import org.auf.to.ChatEvent;
import org.auf.to.Event;

public class NewMessageChatboxController extends Controller {

	@Override
	public void show() {
		String message, id;
		message = (String) request.getAttribute("message");
		id = (String) request.getAttribute("id"); //id del evento
		Event temp = new Event();
		IEventDAO eventdao = EventDAOJDBC.getInstance();
		temp = eventdao.selectEvent(id);
		IChatEventDAO chatdao = new ChatEventDAOJDBC();
		Collection<ChatEvent> listchatevent = chatdao.selectChatEventByEvent(temp);
		ChatEvent chatbox = new ChatEvent();
		chatbox.setMessage(message);
		listchatevent.add(chatbox);
		try {
			response.sendRedirect("?action=showevent&=id" + id);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
